<?php
if (! defined ( 'IN_ADMIN' )) {
	exit ( 'Access Denied' );
}

// 获取限制条件
function getparam($intkeys, $strkeys) {
	$paramarr = array ();
	$urls = array ();
	
	foreach ( $intkeys as $var ) {
		$value = isset ( $_GET [$var] ) ? $_GET [$var] : '';
		if (strlen ( $value )) {
			$paramarr [$var] = intval ( $value );
			$urls [] = "$var=$value";
		}
	}
	
	foreach ( $strkeys as $var ) {
		$value = isset ( $_GET [$var] ) ? trim ( $_GET [$var] ) : '';
		if (strlen ( $value )) {
			$paramarr [$var] = $value;
			$urls [] = "$var=" . rawurlencode ( $value );
		}
	}
	
	return array (
			'param' => $paramarr,
			'urls' => $urls 
	);
}

function multi($start, $perpage, $mpurl) {
	$nexturl = $mpurl . '&perpage=' . $perpage . '&start=' . ($start + $perpage);
	$cureent = $mpurl . '&perpage=' . $perpage . '&start=' . $start;
	$preurl = '';
	if ($start >= $perpage) {
		$preurl = $mpurl . '&start=' . ($start - $perpage);
		$firsturl = $mpurl;
	}
	
	return array (
			'first' => $firsturl,
			'next' => $nexturl,
			'prev' => $preurl,
			'urls' => $cureent
	);
}

// 分页
function multitotal($page, $totalPages, $mpurl) {
    $firsturl = $mpurl. '&page=1';
    $nexturl = '';
    if ($page < $totalPages)
    {
        $nexturl = $mpurl . '&page=' . ($page+1);
    }
    $cureent = $mpurl . '&page=' . $page;
    $preurl = '';
    if ($page>1) {
        $preurl = $mpurl . '&page=' . ($page - 1);
    }
    $lasturl = $mpurl . '&page=' . $totalPages;

    $result =  array (
            'first'     => $firsturl,
            'next' 	    => $nexturl,
            'prev' 	    => $preurl,
            'last'	    => $lasturl,
            'urls' 	    => $cureent,
            'totalPage' => $totalPages,
            'currentPage' => $page
    );
    return $result;
}

function multirec($start, $end, $mpurl, $length) {
	$preurl = '';
	$nexturl = $mpurl . '&start=' .($start+$length);
	if($start>=$length){
		$preurl = $mpurl . '&start=' . ($start - $length);
	}
	$firsturl = $mpurl;

	return array (
			'first' => $firsturl,
			'next' => $nexturl,
			'prev' => $preurl,
			'urls' => $cureent
	);
}

/**
 * 提示信息
 * @param string $message	提示信息
 * @param string $url_forward 跳转地址
 * @param number $second	跳转延时
 */
function cpmessage($message, $url_forward='', $second=1) {
	global $_SGLOBAL, $_SC, $_SCONFIG, $_TPL, $space, $_SN;
	obclean();
	
	//显示
	if($url_forward && empty($second)) {
		header("HTTP/1.1 301 Moved Permanently");
		header("Location: $url_forward");
	} else {
		//显示
		if($url_forward) {
			$message = "<a href=\"$url_forward\">$message</a><script>setTimeout(\"window.location.href ='$url_forward';\", ".($second*1000).");</script>";
		}
		include template('cpmessage');
	}
	exit();
}